<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <link rel="stylesheet" href="../../../resources/styles.css">
  <link rel="icon" type="image/x-icon" href="../../../resources/favicon.ico">
  <title>Tools Component</title>
    <style>
      body {
        margin: 0;
        padding: 0;
      }
      .full-screen {
        width: 100vw;
        height: 100vh;
        position: relative;
        overflow: hidden;
      }
    </style>
</head>
<body>
<div class="full-screen" id="container"></div>
<script type="importmap">
    {
      "imports": {
        "three": "https://unpkg.com/three@0.160.1/build/three.module.js",
        "stats.js/src/Stats.js": "https://unpkg.com/stats-js@1.0.1/src/Stats.js",
        "openbim-components": "../../../resources/openbim-components.js",
        "unzipit": "https://unpkg.com/unzipit@1.4.3/dist/unzipit.module.js"
      }
    }
</script>
<script type="module">

	// Set up scene (see SimpleScene tutorial)

	import * as OBC from 'openbim-components';
	import {unzip} from 'unzipit';

	const container = document.getElementById('container');

	const components = new OBC.Components();

	const sceneComp = new OBC.SimpleScene(components);
	components.scene = sceneComp;
	components.renderer = new OBC.SimpleRenderer(components, container);
	components.camera = new OBC.SimpleCamera(components);
	components.raycaster = new OBC.SimpleRaycaster(components);

	components.init();

	const scene = components.scene.get();
	sceneComp.setup();

	components.camera.controls.setLookAt(10, 10, 10, 0, 0, 0);

	const grid = new OBC.SimpleGrid(components);

  // Set up cloud processor

	const storage = new OBC.CloudStorage(components);
	storage.token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1IjoiNjUwNmYyZjk0NWM4YmM2YTk0Mzg0NjM4IiwiYSI6IjY1NTRjMTJjODRmZTUwOTk4Yzk2YWViYyJ9.orL8C6hAS4Lj6D_kDAeUiGytNVqgpPL2wV9a7sTMpAg";

	// Get all the models

	await storage.update();
	const models = storage.get();
	console.log(models);

	// Delete models

  for(const model of models) {
		storage.delete(model._id);
  }

  // Upload model

	window.ondblclick = async () => {
		await storage.upload("../../../resources/small.ifc");
		console.log("Model uploaded! Starting processing...");
  }

	// Download model (after processing)

  const fragments = new OBC.FragmentManager(components);

  async function loadModel(response) {
		console.log("Model process successful!");
		console.log(response);
  }

	storage.modelProcessed.add(loadModel)


</script>
</body>
</html>
